<template>
	<view class="app">
		<view class="panel">
			<view class="flex-col">
<!-- 				<view class="flex justify-between list" v-for="(item,index) in list.data">
					<view>{{item.openid}}</view>
					<view>{{item.isfollow?'关注':'取消关注'}}</view>
				</view> -->
				<view class="flex justify-center items-center">
					<button @click="loadList">开始检测</button>
				</view>
				<view class="flex justify-center bottomfiexd">
					<view>{{list.total}}个</view>
					<view style="margin-left: 16px;">关{{isfollow.y}} / 取{{isfollow.n}} /总{{isfollow.c}}</view>
					<view style="margin-left: 16px;">{{list.current_page}}/{{list.last_page}}页</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var that,App=getApp(),Comm=getApp().comm;
	export default {
		data() {
			return {
				list:{"total":0,"per_page":0,"current_page":0,"last_page":1,"data":[]},
				isfollow:{
					c:0,
					y:0,
					n:0
				}
			}
		},
		onLoad() {
			that=this;
			// that.loadList();
		},
		methods: {
			async checkOpenid(openid){
				return new Promise((resolve,reject)=>{
					Comm.http('/api/tool/checkfollow',{openid}).then(res=>{
						resolve(res.data);
					}).catch(err=>{
						reject(err);
					});
				});
			},
			loadList(){
				let limit=10,page=this.list.current_page+1;
				
				if(page>this.list.last_page){
					Comm.tips("已到最后一页");
					return;
				}
				Comm.http('/api/tool/authlist',{page,limit}).then(async res=>{
					that.list=res.data;
					that.isfollow.c+=res.data.data.length;
					for (let listItem of res.data.data) {
						that.checkOpenid(listItem.openid).then(res2=>{
							if(res2)
								that.isfollow.y+=1;
							else
								that.isfollow.n+=1;
						});
					}
					window.setTimeout(()=>{
						that.loadList();
					},1000);
					
				});
			}
		}
	}
</script>

<style lang="scss">
	.panel{
		.list{
			padding: 8px 0; border-bottom: 1px solid #f0f0f0;
		}
		.bottomfiexd{
			position: fixed; width: 100vw; height: 45px; line-height: 45px; left: 0; bottom: 0; background-color: #ffffff; border-top: #f0f0f0 2px solid;
		}
	}
</style>
